module.exports = async (ctx, next) => {
  console.log(ctx.path, '判断..');
  if (!validatePath(ctx)) {
    console.log(ctx.path, '重定向');
    ctx.redirect('/login');
  } else {
    console.log('通过重定向');
    await next();
  }
};

function validatePath(ctx) {
  const {path, session} = ctx;
  const isJs = /^\/js\//.test(path);
  const isCss = /^\/css\//.test(path);
  const loginPath = path === '/login';
  const isLogin = !!session.user;
  console.log(isJs, isCss, loginPath, isLogin);
  return isJs || isCss || loginPath || isLogin;
}